home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / ccdsrc.zip / INTER.C < prev    next >
Text File  |  1991-08-23  |  4KB  |  166 lines

  1. /* interlace fields from uosat pics and make even number of pixels per line.
  2.  
  3. 21JUL91 NK6K
  4.  
  5. This program takes a UoSAT-5 CCD 2-field image and interlaces them into
  6. one flat raster file.  It also adds a 0 pixel to the end of each line,
  7. the rg8 program used to convert the raster file to .GIF doesn't like
  8. odd line lengths when using the /2 option.
  9.  
  10. Suggested usage:
  11.  
  12. inter ccdn ccdni
  13. rg8 ccdni. /c612 /r578
  14.  
  15. Harold
  16.  
  17. Added 7/28/91
  18. Remove first four bytes from file, this avoids the wrap-around effect.
  19.  
  20.  
  21. Note:  Some early image files on UO-22 had missing or duplicate blocks,
  22. this will cause this program to emit an incorrect raster file.
  23.  
  24. From UoSAT:
  25.  
  26. The  data  format  that  will be used to  transfer  image  data  from  the 
  27. transputer to the OBC is described as follows.
  28.  
  29. The image frame is composed of two interleaved fields of 288 lines by  611 
  30. pixels  each,  combined to give a total image of 576 by  611.   The  total 
  31. length  of an image file is 352048 bytes, with the extra bytes due to  the 
  32. positional offset between the two fields.
  33.  
  34. When reading the file, the first byte corresponds to the grey level of the 
  35. top  leftmost pixel.  The follow bytes define the pixels to the  right  of 
  36. the  first  one until the end of the first line  is  reached.   Subsequent 
  37. lines  are  aligned below this one for the rest of the first  field  (i.e. 
  38. line 288).  
  39.  
  40. Line  289 is the first line in the second field.  At this point 355  bytes 
  41. (i.e.  half  a  line) must be read and discarded to ensure  that  the  two 
  42. fields align properly.
  43.  
  44. Because the two fields are interlaced, the lines in the second field  must 
  45. be  placed in between the lines of the first field as shown  below.   This 
  46. implies that when the first field is displayed, adequate room must be left 
  47. for the insertion of the second field.
  48.  
  49. When a full frame is displayed the arrangement of the lines should be:
  50.  
  51.      Line 1
  52.      Line 289
  53.      Line 2
  54.      Line 290
  55.      Line 3
  56.      ....
  57.      ....
  58.      Line 574
  59.      Line 287
  60.      Line 575
  61.      Line 288
  62.      Line 576.
  63.  
  64. */
  65. #include <stdio.h>
  66. #include <dos.h>
  67. #include <fcntl.h>
  68. #include <sys\types.h>
  69. #include <sys\stat.h>
  70.  
  71. #define LINE_SIZE 611
  72. #define NUM_LINE_FIELD 288
  73.  
  74.  
  75. long start_field_2;
  76. int lines=0;
  77. int skip_lines=0;
  78.  
  79. char buff[LINE_SIZE+1];
  80. int fillval=0;
  81.  
  82. main(argc,argv)
  83. int argc;
  84. char *argv[];
  85. {
  86.  
  87.     int fi1,fi2,fo;
  88.     int i;
  89.  
  90.     start_field_2 = ((long)LINE_SIZE*(long)NUM_LINE_FIELD)+355l;
  91.  
  92.  
  93.     if (argc<2) {
  94.         printf ("usage: inter input output [skip_lines]\n");
  95.         printf ("skip - number of lines from start of image to not\n");
  96.         printf ("include in the output file");
  97.         exit(1);
  98.     }
  99.  
  100.     if (argc>3) skip_lines = atoi(argv[3]);
  101.  
  102.     if ((fi1= open(argv[1], O_BINARY)) == -1){
  103.         printf("cannot open: %s\n",argv[1]);
  104.         perror("On input file");
  105.         exit(1);
  106.     }
  107.  
  108.     if ((fi2= open(argv[1], O_BINARY)) == -1){
  109.         printf("cannot open: %s\n",argv[1]);
  110.         perror("On input file");
  111.         exit(1);
  112.     }
  113.  
  114.     lseek(fi2,start_field_2+4l,SEEK_SET);
  115.     lseek(fi1,4l,SEEK_SET);
  116.  
  117.  
  118.     if ((fo = open(argv[2], 0)) != -1){
  119.         printf("output file exists.  Aborted\n");
  120.         exit(1);
  121.     }
  122.  
  123.     if ((fo = open(argv[2],O_CREAT | O_TRUNC | O_BINARY | O_RDWR, S_IREAD | S_IWRITE)) == -1) {
  124.         printf("cannot open: %s\n",argv[2]);
  125.         perror("On output file");
  126.         exit(1);
  127.     }
  128.  
  129.     
  130.     buff[LINE_SIZE+1]=0;
  131.     for (i=0;i<NUM_LINE_FIELD;i++) {
  132.  
  133.             /* If file is short, fill with zeroes */
  134.         memset(buff,0,LINE_SIZE+1);
  135.         if (read(fi1, buff, LINE_SIZE)==-1) {
  136.             perror("On input file 1st field\n");
  137.             exit(1);
  138.         }
  139.         if (lines >= skip_lines) {
  140.          if (write(fo,buff,LINE_SIZE+1)==-1) {
  141.             perror("On output file 1st field\n");
  142.             exit(1);
  143.          }
  144.         }
  145.  
  146.         memset(buff,0,LINE_SIZE+1);
  147.         if (read(fi2, buff, LINE_SIZE)==-1) {
  148.             perror("On input file 2nd field\n");
  149.             exit(1);
  150.         }
  151.  
  152.         if (lines >= skip_lines) {
  153.          if (write(fo,buff,LINE_SIZE+1)==-1) {
  154.             perror("On output file 2nd field\n");
  155.             exit(1);
  156.          }
  157.         }
  158.         lines++;
  159.     }
  160.     close (fo);
  161.     close (fi1);
  162.     close (fi2);
  163.  
  164. }
  165.  
  166.